//
// Created by luqihua on 2023/2/23.
//
#include <jni.h>
#include "android/log.h"

#define TAG "security_constants.cpp"

const char defaultKey[] = "ruijiezh";
const char defaultIV[] = "abcdabcdabcdabcd";


const char publicKey[] = "-----BEGIN PUBLIC KEY-----\n"\
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+7EekilxwIgTyxT5kgNs5olHA\n"\
"UtcC0rJfKXHReD/++EfHLwgGnvk8xzR5AvHjzgcgOIqBe9MOLRtDiJ+ZAXBasnkk\n"\
"nGvseU5vuWnRXyQREnEwvq6lQS7mrfH6xIvy161BdIzZo2feUbPZuEp/MDOVb5IX\n"\
"1xCWh3iCCfmKASkurwIDAQAB\n"\
"-----END PUBLIC KEY-----\n";

const char privateKey[] = "-----BEGIN PRIVATE KEY-----\n"\
"MIICeQIBADANBgkqhkiG9w0BAQEFAASCAmMwggJfAgEAAoGBAL7sR6SKXHAiBPLF\n"\
"PmSA2zmiUcBS1wLSsl8pcdF4P/74R8cvCAae+TzHNHkC8ePOByA4ioF70w4tG0OI\n"\
"n5kBcFqyeSSca+x5Tm+5adFfJBEScTC+rqVBLuat8frEi/LXrUF0jNmjZ95Rs9m4\n"\
"Sn8wM5VvkhfXEJaHeIIJ+YoBKS6vAgMBAAECgYEAqtSgBgoHTA4kf1Udzq+9eIRU\n"\
"wdFdsZj1IVDkFpmSKYHeN8tNUx9Lw6Y6vUx1Q3BFz/7Hb7Rr1HNnwbWtmCpBbFdA\n"\
"L/3G8Og2L0eECs5I2p1ipFuyf7aajzOZd/hHLV9YLKngfE9MTTk934zyli2FGFQ/\n"\
"9uOvmS7f9Xx0h9euBwECQQD6Fut3f0y8vJ4TXHB1//tX3sF0inHYMfopGnJJzCJI\n"\
"SP1pzo9976EtU38wnjs152f28uhO4OBnR/+Www4Ptw8pAkEAw29kq2zN6T4bJAwK\n"\
"kOeOVRePoyuOGv2Y2MOBasHisVCEA/r2U8/8TBKSgJvWUBgLRhWIXXrQU31Bb3eQ\n"\
"xmSCFwJBALcnKfMt64kdqbcML+B7RBuqK4uqCI4Iq+iGUcTyFvlRWyWt/TCB2kxT\n"\
"pgZ5G2vyuRUF+FQsJKv+8pP67cVcj2ECQQCz9U/SlkbpPnoJcFkOY1ppul9WVdXt\n"\
"vpTPDP+PiWcv9T8K1z2ZoYvllLh4Woc2i11eNJez1FIeftkRRhz2wjgTAkEAtYzk\n"\
"onmlGAvl5i/ORsED+2MEhHsTwP8qgGZvlCWusqW1GBdXitZmFIWSREYnD17+ZjAl\n"\
"peU/aK0h4zIxA/4Syg==\n"\
"-----END PRIVATE KEY-----\n";


void printLog(JNIEnv *env, jclass clazz, const char *method) {
    jfieldID fd = env->GetStaticFieldID(clazz, "sDebug", "Z");
    jboolean debug = env->GetStaticBooleanField(clazz, fd);
    if (debug) {
        __android_log_print(ANDROID_LOG_DEBUG, TAG, __FUNCTION__, method);
    }
}

extern "C"
JNIEXPORT jstring JNICALL
Java_com_lu_security_key_DefaultKey_nGetPrivateKey(JNIEnv *env, jclass clazz) {
    printLog(env, clazz, __FUNCTION__);
    return env->NewStringUTF(privateKey);
}
extern "C"
JNIEXPORT jstring JNICALL
Java_Java_com_lu_security_key_DefaultKey_nGetPublicKey(JNIEnv *env, jclass clazz) {
    printLog(env, clazz, __FUNCTION__);
    return env->NewStringUTF(publicKey);
}
extern "C"
JNIEXPORT jstring JNICALL
Java_Java_com_lu_security_key_DefaultKey_nDefaultKey(JNIEnv *env, jclass clazz) {
    printLog(env, clazz, __FUNCTION__);
    jstring result = env->NewStringUTF(defaultKey);
    return result;
}
extern "C"
JNIEXPORT jstring JNICALL
Java_Java_com_lu_security_key_DefaultKey_nDefaultIV(JNIEnv *env, jclass clazz) {
    printLog(env, clazz, __FUNCTION__);
    jstring result = env->NewStringUTF(defaultIV);
    return result;
}